<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	template="/WEB-INF/template/template.xhtml">
	
	<ui:define name="body">
		
		<h:form id="formCadastroNoticia">
			
			<div class="body_center_100" style="height: 100%;">
				<rich:panel>
					
					<f:facet name="header">
        				NOTICIAS
        				<h:commandButton value="Buscar" action="#{noticiaAdminMB.buscar}"></h:commandButton>
        				<h:commandButton value="Salvar" action="#{noticiaAdminMB.salvar}"></h:commandButton>
        				<h:commandButton value="Limpar" action="#{noticiaAdminMB.limpar}"></h:commandButton>
					</f:facet>
					
					<h:panelGrid columns="2">
						<h:outputLabel value="Título" />
						<h:inputText value="#{noticiaAdminMB.noticiaBean.titulo}" maxlength="300"></h:inputText>
						
						<h:outputLabel value="Sub-Título" />
						<h:inputText value="#{noticiaAdminMB.noticiaBean.subTitulo}" maxlength="300"></h:inputText>
						
						<h:outputLabel value="Fonte:" />
						<h:outputLabel value="#{noticiaAdminMB.fonteNew.descricao}" />
						
						<h:outputLabel value="Autor:" />
						<h:inputText value="#{noticiaAdminMB.noticiaBean.autor}" maxlength="70"></h:inputText>
						
						<h:outputLabel value="Data da Notícia" />
						<rich:calendar id="cadDatNoticia" value="#{noticiaAdminMB.noticiaBean.dataNoticia}"
								datePattern="dd/M/yy hh:mm a" inputSize="16"
								showApplyButton="true" cellWidth="24px" cellHeight="22px" style="width:200px"/>
						
						<h:outputLabel value="Ativo:" />
						<h:selectBooleanCheckbox value="#{noticiaAdminMB.noticiaBean.status}"></h:selectBooleanCheckbox>

						<h:outputLabel value="Categoria:" />
						<h:selectOneMenu id="cadCodCategoria" value="#{noticiaAdminMB.noticiaBean.categoria.idCategoria}">
							<f:selectItem itemLabel="Selecione..." itemValue="" />
							<f:selectItems value="#{noticiaAdminMB.categoriaBeans}" var="categoriaBean" 
								itemLabel="#{categoriaBean.descricao}" itemValue="#{categoriaBean.idCategoria}" />
						</h:selectOneMenu>
						
						<h:outputLabel value="Texto:" />
						<h:panelGroup style="height:300px;width:400px;" layout="block">
							<rich:editor id="editor" width="400" height="200" value="#{noticiaAdminMB.noticiaBean.texto}"/>
						</h:panelGroup>
						
						<h:outputLabel value="Anexo:" />
						<rich:column>
							<rich:panel id="pgImagem" rendered="#{noticiaAdminMB.mostraImagem() == true}">
	            				<h:outputLabel value="#{noticiaAdminMB.noticiaBean.imagem} (#{noticiaAdminMB.noticiaBean.tamanhoImagem})" />
	            				<h:commandLink action="#{noticiaAdminMB.downloadArquivoListener()}">
									<h:graphicImage  library="download.png" url="/resources/images/download.png"></h:graphicImage>
								</h:commandLink>
								<h:commandLink action="#{noticiaAdminMB.deletarAnexo()}">
									<h:graphicImage  library="delete.png" url="/resources/images/delete.png"></h:graphicImage>
								</h:commandLink>
	            			</rich:panel>
	            			
							<rich:fileUpload fileUploadListener="#{noticiaAdminMB.anexar}"
	               				maxFilesQuantity="1"
	               				maxRequestSize="300000"
                         		immediateUpload="#{true}"
	                			id="upload"
	                			acceptedTypes="jpg, gif, png, bmp" 
	                			ontyperejected="alert('Somente JPG, GIF, PNG e BMP são aceitos!');" />
            			</rich:column>
            		
					</h:panelGrid>

					<rich:dataTable value="#{noticiaAdminMB.noticiaBeans}" var="noticiaBean">
						<h:column>
							<f:facet name="header">Título</f:facet>
							<h:outputText value="#{noticiaBean.titulo}"></h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Data da Notícia</f:facet>
							<h:outputText value="#{noticiaBean.dataNoticia}">
								<f:convertDateTime pattern="dd/MM/yyyy hh:mm"/>  
							</h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Autor</f:facet>
							<h:outputText value="#{noticiaBean.autor}"></h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Ativo</f:facet>
							<h:outputText value="#{noticiaBean.status == true ? 'Sim': 'Não' }"></h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Editar</f:facet>
							<h:commandLink action="#{noticiaAdminMB.editar(noticiaBean)}">
								<h:graphicImage  library="edit.png" url="/resources/images/edit.png"></h:graphicImage>
							</h:commandLink>
						</h:column>
						<f:facet name="footer">  
				        	<rich:dataScroller></rich:dataScroller>  
				      	</f:facet> 
					</rich:dataTable>

				</rich:panel>
			</div>
		</h:form>
	</ui:define>
</ui:composition>